package com.hd.tiyu.yuejian.Adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.hd.tiyu.yuejian.JavaBean.FaTie;
import com.hd.tiyu.yuejian.R;
import com.squareup.picasso.Picasso;

import java.util.List;


/**
 * Created by love on 2017/11/3.
 */

public class FaTieAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private List<FaTie> mDataList;
    private LayoutInflater mLayoutInflater;

    public FaTieAdapter(Context mContext, List<FaTie> mDataList){
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }
    public class ViewHolder extends RecyclerView.ViewHolder{
        TextView title,fatie_time;
        ImageView fatie_photo;

        public ViewHolder(View itemView) {
            super(itemView);
            title=itemView.findViewById(R.id.tex_fatietitle);
            fatie_time=itemView.findViewById(R.id.tex_fatietime);
            fatie_photo=itemView.findViewById(R.id.imag_fatie_photo);
        }
    }



    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view=mLayoutInflater.from(parent.getContext()).inflate(R.layout.fatie_item,parent,false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        final FaTie data=mDataList.get(position);
        if (data!=null){
            ViewHolder viewHolder=(ViewHolder) holder;
            viewHolder.title.setText(data.getTitle());
            viewHolder.fatie_time.setText(data.getUpdate_time());
            Picasso.with(mContext)
                    .load("http://172.24.10.175/workout/Uploads/"+data.getThumb0())
                    .resize(200,200).centerCrop()
                    .into(viewHolder.fatie_photo);
        }
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }
}
